<template>
    <div class="deal">
        <van-nav-bar :title="$t('my.records')" leftArrow @click-left="_return"/>
        <div class="dealMain">
            <ul>
                <li v-for="item in dealList">
                    <van-row type="flex" justify="space-between" align="center">
                        <van-col>
                            <p>{{item.type === 1 ? '+' : '-'}}{{Number(item.num)}} {{item.coin_name.toUpperCase()}}</p>
                            <span>{{item.add_time}}</span>
                        </van-col>
                        <van-col>
                            <p class="org">{{item.category}}</p>
                            <span>{{item.category}} <span>{{item.status}}</span></span>
                        </van-col>
                    </van-row>
                </li>
            </ul>
        </div>
    </div>
</template>

<script>
    import moment from 'moment'
    export default {
        data() {
            return {
                dealList:[]
            }
        },
        methods: {
            _return(){
                this.$emit('_return')
            },
            getData(){
                this.$api.post('user/mingxi')
                    .then(res =>{
                        this.dealList = res.detail.concat(res.gz)
                        let tip = res.category
                        this.dealList.map(item =>{
                            item.category = tip[item.category]
                            item.add_time = moment(item.add_time*1000).format('YYYY-MM-DD')
                            if(item.category != '26'){
                                switch (item.status) {
                                    case 0:
                                        item.status = '审核中'
                                        break;
                                    case 1:
                                        item.status = '成功'
                                        break;
                                    case 2:
                                        item.status = '失败'
                                        break;
                                }
                            }
                        })
                        this.dealList.sort(compare)
                        function compare(value1,value2) {
                            if (value1.add_time < value2.add_time) {
                                return 1;
                            }else if (value1.add_time > value2.add_time) {
                                return -1;
                            }else{
                                return 0;
                            }
                        }
                    })
            }
        },
        created() {
            this.getData()
        },
        mounted() {
            this.$emit('disappear')
        },
    }
</script>

<style lang="stylus" scoped>
    bac = linear-gradient(90deg,rgba(42,42,42,1) 0%,rgba(46,46,46,1) 100%);
    font = #CBAF89
    fonts = #898989
    [class*=van-hairline]::after{
        border: none;
    }
    .dealMain
        width 94%
        margin 0 auto
        li
            padding 15px
            border-radius 5px
            margin-bottom 5px
            border-bottom 1px solid #ebebeb
            .van-col
                p
                    font-size 20px
                    color #23ba92
                p.org
                    font-size 16px
                    color #f6543e
                span
                    font-size 10px
                    color fonts
                &:last-child
                    text-align right

</style>